package edu.polsl.bio.str.manager.logic;

import edu.polsl.bio.str.manager.command.JobLoaderCommand;
import edu.polsl.bio.str.manager.messaging.ManagerMessagePublisher;
import edu.polsl.bio.str.manager.vo.DotPlotRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * //todo class description
 * <p/>
 * Created on: Jun 14, 2011 1:42:03 PM <br/>
 * <a href="http://www.polsl.pl">www.polsl.pl</a>
 *
 * @author lukasz.olczak@polsl.pl
 */
public class DotPlotJobBeanImpl implements DotPlotJobBean, ApplicationContextAware {
  /**
   * slf4j Logger.
   */
  private static final Logger log = LoggerFactory.getLogger(DotPlotJobBeanImpl.class.getName());

  private ManagerMessagePublisher managerEventPublisher;

  private ApplicationContext applicationContext;

  @Override
  public void handleDotPlotRequest(Long refIndividualId, Long queryIndividualId, Long refChromosomeId,
                                   Long queryChromosomeId) throws Exception {
    log.info("Handling dot plot job request...");
    DotPlotRequest dotPlotRequest = new DotPlotRequest();
    dotPlotRequest.setRefIndividualId(refIndividualId);
    dotPlotRequest.setQueryIndividualId(queryIndividualId);
    dotPlotRequest.setRefChromosomeId(refChromosomeId);
    dotPlotRequest.setQueryChromosomeId(queryChromosomeId);
    JobLoaderCommand cmd = (JobLoaderCommand) applicationContext.getBean("jobLoaderCmd");
    cmd.setContext(dotPlotRequest);
    cmd.setProxy(cmd);
    managerEventPublisher.publishLoaderCommand(cmd);
  }

  @Override
  public void setApplicationContext(ApplicationContext applicationContext) {
    this.applicationContext = applicationContext;
  }

  public void setManagerEventPublisher(ManagerMessagePublisher managerEventPublisher) {
    this.managerEventPublisher = managerEventPublisher;
  }
}
